package com.huarui.initial.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huarui.initialItem.model.InitialItem;

public class InitialItemErrors {
     
	public static InitialItem setErrorsProperty(InitialItem initialItem){
		StringBuffer stringBuffer=new StringBuffer();
		int isError=2;//0正确,1错误,2警告
		Map<Integer, String> map=new HashMap<Integer, String>();
		List<Integer> list=new ArrayList<Integer>(10);
		if(initialItem.getPartId()==null){
			stringBuffer.append("标准库中无该零件,");
			list.add(1);
		}
		if(initialItem.getCode()==null){
			stringBuffer.append("编码为空,");
			list.add(1);
		}
		if(initialItem.getRetailPrice()==null||initialItem.getRetailPrice().intValue()==0){
			stringBuffer.append("售价为0,");
			list.add(1);
		}
		if(initialItem.getSource()==null){
			stringBuffer.append("来源为空,");
			list.add(1);
		}
		if(initialItem.getStoreId()==null||initialItem.getStoreId()==0){
			stringBuffer.append("仓库为空,");
			list.add(1);
		}
		if(initialItem.getQuantity()==null||initialItem.getQuantity()==0){
			stringBuffer.append("数量为0,");
			list.add(2);
		}
		if(list.size()==0){
			initialItem.setErrorType(0);
			initialItem.setCheckResult(null);
		}else{
			for(Integer errorType:list){
				if(errorType==1){
					initialItem.setCheckResult(stringBuffer.substring(0, stringBuffer.length()-1));
					initialItem.setErrorType(errorType);
					return initialItem;
				}
			}
			initialItem.setErrorType(2);
			initialItem.setCheckResult(stringBuffer.substring(0, stringBuffer.length()-1));
		}
		return initialItem;

	}


}
